package com.lianxian.xindong.life.adapter;

import android.content.Context;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.lianxian.xindong.life.R;
import com.lianxian.xindong.life.R2;
import com.lianxian.xindong.life.util.GlideUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class BusinessPhotoAdapter extends RecyclerView.Adapter {
    Context context;
    List<String> picUrls;

    public BusinessPhotoAdapter(Context context, List<String> picUrls) {
        this.context = context;
        this.picUrls = picUrls;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
        View view = layoutInflater.inflate(R.layout.item_business_photo, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        String url = picUrls.get(position);
        ViewHolder viewHolder = (ViewHolder) holder;
        GlideUtil.GlideWithPlaceHolder(context, url).into(viewHolder.photoIV);
    }

    @Override
    public int getItemCount() {
        return picUrls.size();
    }
    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R2.id.business_photo)
        ImageView photoIV;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
